package br.unip.tcc.domotic.teste;

import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

public class TesteConnection {
	
	public static void main(String[] args) {
		
		try {
			Class.forName("org.postgresql.Driver");
			Connection conn = DriverManager.getConnection("jdbc:postgresql://localhost:5432/domotic", "postgres", "guedes");
			
			DatabaseMetaData databaseMetaData = conn.getMetaData(); //get MetaData to confirm connection
		    System.out.println("Connection to "+databaseMetaData.getDatabaseProductName()+" "+
		    						databaseMetaData.getDatabaseProductVersion()+" successful.\n");
		    
		    PreparedStatement pst = (PreparedStatement) conn.prepareStatement("Select * from home");
		    ResultSet rs = pst.executeQuery();
		    while(rs.next()){
		    	System.out.println(rs.getInt(1));
		    }
		    
		    
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
